$(function(){ 
	window.SubmenuView = Backbone.View.extend({
		el : $('.menu'), 
		initialize : function() {
			this.template = _.template($('#submenu-template').html());
			this.collection.bind('reset', _.bind(this.render, this));
		},

		render : function() { 
			var renderedContent = this.template({ submenuItems : this.collection.toJSON() });
			
			$(this.el).html(renderedContent);
			if (this.collection.length > 0){
				$(this.el).show();
			}else{
				$(this.el).hide();
			}
			
			$(".menu li").click(
				function(){
					$(".menu li").removeClass("selected");
					$(this).addClass("selected");
				}
			);
			return this;
		}

	});
});
